import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../bean/transaction_history.dart';

class AssetsHistoryPage extends StatefulWidget{
  final List<TransactionHistory> historyList;

  const AssetsHistoryPage({super.key,required this.historyList});

  @override
  State<StatefulWidget> createState() => _AssetsHistoryPageState();

}

class _AssetsHistoryPageState extends State<AssetsHistoryPage>{
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.symmetric(vertical: 20,horizontal: 30.0),
            child: Text(
              'History',
              style: TextStyle(fontWeight: FontWeight.bold,color: Colors.black),
            ),
          ),
          Expanded(
            child: ListView.separated(
              padding: EdgeInsets.symmetric(horizontal: 30),
              itemCount: widget.historyList.length,
              itemBuilder: (context, index) {
                final historyItem = widget.historyList[index];
                return Padding(
                  padding:
                  const EdgeInsets.symmetric(vertical: 8.0),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment:
                        MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            '${historyItem.amountValue} ${historyItem.amountUnit}',
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                color:Colors.black),
                          ),
                          Text(
                            historyItem.status,
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(color: Colors.grey,fontSize: 12),
                          )
                        ],
                      ),
                      SizedBox(height: 10,),
                      Align(
                        alignment: Alignment.centerRight,
                        child: Text(
                          DateUtil.formatDateMs(historyItem.createTime),
                          style: TextStyle(color: Colors.grey,fontSize: 12),
                        ),
                      ),
                    ],
                  ),
                );
              },
              separatorBuilder:
                  (BuildContext context, int index) {
                return Divider();
              },
            ),
          ),
        ],
      ),
    );
  }

}